Next | Prev | Up | Top | Contents | Index

Listing Symbol Table Information: nm

The nm tool lists symbol table information for object files and archive files.


nm Syntax

The syntax for nm is:

nm options filename1 [filename2...filenamen]

options

One or more of the options listed in Table 2-8.

filename

Specifies the object files or archive files from which symbol table information is to be extracted. If you do not specify a filename, nm assumes the file is named a.out.

nm Symbol Table Options

Table 2-8 lists nm symbol table options. For more information, see the nm(1) reference page.

Symbol Table nm Options
Option Purpose
-aPrints debugging information.
-APrints the listing in System V format (default).
-bPrints the value field in octal.
-BPrints the listing in BSD format.
-CPrints decoded C++ names.
-dPrints the value field in decimal (the default for System V output).
-gPrints globally visible names.
-hSuppresses printing of headers.
-lProduces a long listing.
-nSorts external symbols by name for System V format. Sorts all symbols by value for BSD format (by name is the BSD default output).
-oPrints value field in octal (System V output). Prints the filename immediately before each symbol name (BSD output).
-pProduces easily parsible, terse output similar to the BSD format.
-rPrepends the name of the object file or archive to each output line.
-TTruncates characters in exceedingly long symbol names; inserts an asterisk as the last character of the truncated name. This option may make the listing easier to read.
-uPrints only undefined symbols.
-vSorts external symbols by value (default for BSD format).
-VPrints the version number of nm.
-xPrints the value field in hexadecimal.

Table 2-9 defines the one-character codes shown in an nm listing. Refer to the example that follows the table for a sample listing.

Character Code Meanings
KeyDescription
aLocal absolute data
AExternal absolute data
bLocal zeroed data
BExternal zeroed data
CCommon data
dLocal initialized data
DExternal initialized data
ESmall common data
GExternal small initialized data
NNil storage class (unused external reference)
rLocal read-only data
RExternal read-only data
sLocal small zeroed data
SExternal small zeroed data
tLocal text
TExternal text
UExternal undefined data
VExternal small undefined data


nm Example of Obtaining a Symbol Table Listing

This example demonstrates how to obtain a symbol table listing. Consider the following program, tnm.c:

#include <stdio.h>
#include <math.h>
#define LIMIT 12
int unused_item = 14;
double mydata[LIMIT];

main()
{
    int i;
    for(i = 0; i < LIMIT; i++) {
        mydata[i] = sqrt((double)i);
    }
    return 0;
}
Compile the program into an object file by entering:

cc -c tnm.c

To obtain symbol table information for the object file tnm.o in BSD format, use the nm -B command:

0000000000 T main
0000000000 B mydata
0000000000 U sqrt
0000000000 D unused_item
00000000 N _bufendtab
To obtain symbol table information for the object file tnm.o in SVR4 format, use the nm command without any options:

Symbols from tnm.o:

[Index]   Value     Size    Class    Type         Section    Name

[0]     |        0|        |File    |ref=4       |Text     | tnm.c
[1]     |        0|        |Proc    |end=3 int   |Text     | main
[2]     |      116|        |End     |ref=1       |Text     | main
[3]     |        0|        |End     |ref=0       |Text     | tnm.c
[4]     |        0|        |File    |ref=6       |Text     | /usr/include/math.h
[5]     |        0|        |End     |ref=4       |Text     | /usr/include/math.h
[6]     |        0|        |Global  |            |Data     | unused_item
[7]     |        0|        |Global  |            |Bss      | mydata
[8]     |        0|        |Proc    |ref=1       |Text     | main
[9]     |        0|        |Proc    |            |Undefined| sqrt
[10]    |        0|        |Global  |            |Undefined| _gp_disp

Next | Prev | Up | Top | Contents | Index